<template>
  <s-layout class="widthdraw-log-wrap" title="充值记录">
    <su-sticky>
      <!-- 统计 -->
      <my-tabs
        :list="tabMaps"
        @change="onChange"
        :scrollable="false"
        :current="state.currentTab"
      ></my-tabs>
    </su-sticky>
    <!-- 记录卡片 -->
    <view class="wallet-log-box ss-p-b-30">
      <view class="log-list" v-for="item in state.pagination.data" :key="item">
        <view class="item ss-flex ss-row-between">
          <view class="item-left ss-flex-col ss-row-around">
            <view class="item-status" :class="
              item.status === -1
                ? 'danger-color'
                : item.status === 2
                ? 'success-color'
                : 'warning-color'
            ">
              已通过
            </view>
            <view class="item-time">
              {{ item.updatetime }}
            </view>
          </view>
          <view class="item-right primary-color">
            {{ item.trade_order.pay_fee }}￥
          </view>
        </view>
        <view v-if="item.reason" class="item-bottom ss-flex ss-row-between">
          <view class="label">原因</view>
          <view class="tips">{{item.reason}}</view>
        </view>
      </view>
    </view>
    <s-empty
      v-if="state.pagination.total === 0"
      icon="/static/comment-empty.png"
      text="暂无充值记录"
    ></s-empty>
    <uni-load-more
      v-if="state.pagination.total > 0"
      :status="state.loadStatus"
      :content-text="{
        contentdown: '上拉加载更多',
      }"
      @tap="loadmore"
    />
  </s-layout>
</template>

<script setup>
  import { reactive } from 'vue';
  import sheep from '@/sheep';
  import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  import _ from 'lodash';
  import SLayout from '@/sheep/components/s-layout/s-layout.vue';

  const tabMaps = [
    {
      name: '全部',
      value: 'wallet',
    },
    {
      name: '已通过',
      value: 'packet',
    },
    {
      name: '审核中',
      value: 'transfer',
    }, {
      name: '已拒绝',
      value: 'withdraw',
    },
  ];
  const state = reactive({
    currentTab: 0,
    pagination: {
      data: [],
      current_page: 1,
      total: 1,
      last_page: 1,
    },
    loadStatus: '',
  });

  function onChange(e) {
    state.pagination.current_page = 1;
    state.currentTab = e.index;
    getLogList();
  }

  async function getLogList(page = 1, list_rows = 5) {
    let status=state.currentTab==0?'':state.currentTab
    const res = await sheep.$api.trade.orderLog({ type: 'recharge',status, list_rows, page });
    if (res.code === 1) {
      let logList = _.concat(state.pagination.data, res.data.data);
      state.pagination = {
        ...res.data,
        data: logList,
      };
      if (state.pagination.current_page < state.pagination.last_page) {
        state.loadStatus = 'more';
      } else {
        state.loadStatus = 'noMore';
      }
    }
  }

  // 加载更多
  function loadmore() {
    if (state.loadStatus !== 'noMore') {
      getLogList(state.pagination.current_page + 1);
    }
  }

  onLoad(() => {
    // getLogList();
  });
  onReachBottom(() => {
    loadmore();
  });
</script>

<style lang="scss" scoped>
  // 记录卡片
  .log-list {
    padding:0 30rpx;
    font-size: 24rpx;
    border-bottom: 1px solid #333333;
    .item {
      .item-left{
        min-height: 164rpx;
      }
      .item-status{
        font-size: 32rpx;
      }
      .item-time{
        color: #767676;
      }
      .item-right{
        font-size: 38rpx;
      }
    }
    .item-bottom{
      padding:25rpx 0;
      .label{
        color: #767676;
      }
      .tips{
        color: #E6E6E6;
      }
    }
  }

  .primary-color {
    color: #00A1FF;
  }

  .warning-color {
    color: #F17126;
  }

  .danger-color {
    color: #FF0000;
  }

  .success-color {
    color: #13C093;
  }
</style>
